package com.atguigu.flink.chapter06;

import com.atguigu.flink.bean.WaterSensor;
import com.atguigu.flink.function.WaterSensorMapFunction;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.KeyedStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @Author lzc
 * @Date 2023/6/21 14:27
 */
public class ProcessDemo {
    public static void main(String[] args) {
        Configuration conf = new Configuration();
        conf.setInteger("rest.port", 2000);
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
        env.setParallelism(1);
    
        KeyedStream<WaterSensor, String> s1 = env
            .socketTextStream("hadoop162", 9999)
            .map(new WaterSensorMapFunction())
            //.process(new ProcessFunction<WaterSensor, Object>() {})
            .keyBy(WaterSensor::getId);
        //            .process(new KeyedProcessFunction<String, WaterSensor, Object>() {})
        
//        s1.connect(s1).process(new KeyedCoProcessFunction<>())
        
        try {
            env.execute();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
